home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / gnome-games / aisleriot / games / accordion.scm next >
Encoding:
Text File  |  2009-04-14  |  5.6 KB  |  251 lines

  1. ; AisleRiot - accordion.scm
  2. ; Copyright (C) 2008 Ed Sirett <ed@makewrite.demon.co.uk>
  3. ;
  4. ; This game is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2, or (at your option)
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  17. ; USA
  18.  
  19. (define row1 '(0 1 2 3 4 5 6 7 8 ))
  20. (define row2 '(9 10 11 12 13 14 15 16 17 ))
  21. (define row3 '(18 19 20 21 22 23 24 25 26 ))
  22. (define row4 '(27 28 29 30 31 32 33 34 35 ))
  23. (define row5 '(36 37 38 39 40 41 42 43 44 ))
  24. (define row6 '(45 46 47 48 49 50 51 ))
  25.  
  26.  
  27. (define (add-full-line)
  28.   (add-normal-slot '() )
  29.   (add-normal-slot '() )
  30.   (add-normal-slot '() )
  31.   (add-normal-slot '() )
  32.   (add-normal-slot '() )
  33.   (add-normal-slot '() )
  34.   (add-normal-slot '() )
  35.   (add-normal-slot '() )
  36.   (add-normal-slot '() )
  37.   (add-carriage-return-slot)
  38. )
  39.  
  40. (define (new-game)
  41.  
  42.   (initialize-playing-area)
  43.   (set-ace-low)
  44.   (make-standard-deck)
  45.   (shuffle-deck)
  46.  
  47.  
  48.   (add-full-line)
  49.   (add-full-line)
  50.   (add-full-line)
  51.   (add-full-line)
  52.   (add-full-line)
  53.   (add-normal-slot '() )
  54.   (add-normal-slot '() )
  55.   (add-normal-slot '() )
  56.   (add-normal-slot '() )
  57.   (add-normal-slot '() )
  58.   (add-normal-slot '() )
  59.   (add-normal-slot '() )
  60.  
  61.   (deal-cards-face-up-from-deck DECK (append row1 row2 row3 row4 row5 row6))
  62.   (give-status-message)
  63.   (list 9 6)
  64. )
  65.  
  66.  
  67. (define (recalc-score last-slot) 
  68.   (if 
  69.     (not (empty-slot? last-slot)) 
  70.     0 
  71.     (+ 1 (recalc-score (- last-slot 1)))
  72.   )
  73. )
  74.  
  75. (define (give-status-message)
  76.   (set-score! (recalc-score 51))
  77. )
  78.  
  79.  
  80.  
  81.  
  82.  
  83. (define (button-clicked slot-id) 
  84.   #f
  85. )
  86.  
  87. (define  (sidle-up first-slot)
  88.     (if (and (< first-slot 51)
  89.              (not (empty-slot? (+ first-slot 1)))
  90.              (empty-slot? first-slot)
  91.         )
  92.         (and  
  93.             (move-n-cards! (+ first-slot 1) first-slot (list (get-top-card (+ first-slot 1))))
  94.             (remove-card (+ first-slot 1))
  95.             (sidle-up (+ first-slot 1))
  96.         )
  97.         #t
  98.     )
  99. )
  100.  
  101.  
  102. (define (do-action end-slot start-slot card-list)
  103.       (and
  104.           (remove-card end-slot) 
  105.           (move-n-cards! start-slot end-slot card-list)
  106.           (if (not (empty-slot? start-slot)) (remove-card start-slot) #t)
  107.           (sidle-up start-slot)
  108.           (give-status-message)
  109.       )
  110. )
  111.  
  112. (define (button-released start-slot card-list end-slot)
  113.    (if ( droppable? start-slot card-list end-slot)
  114.       (do-action end-slot start-slot card-list) 
  115.       #f  
  116.   )
  117. )
  118.  
  119. (define (matches-in-rank slot1 card) 
  120.    (and (>= slot1 0) 
  121.         (= (get-value (get-top-card slot1)) 
  122.            (get-value card)
  123.         )
  124.    )
  125. )
  126.  
  127. (define (matches-in-suit slot1 card) 
  128.    (and (>= slot1 0) 
  129.         (= (get-suit (get-top-card slot1)) 
  130.            (get-suit card)
  131.         )
  132.    )
  133. )
  134.  
  135. (define (button-pressed slot-id card-list) 
  136.    (if (not (empty-slot? slot-id))
  137.          (> slot-id 0)
  138.          #f
  139.    )
  140. )
  141.  
  142.  
  143.  
  144.  
  145. (define (playable? from-slot card)
  146.    (or (playable-1? from-slot card) 
  147.        (playable-3? from-slot card)
  148.    )
  149. )
  150.  
  151. (define (playable-3? from card)
  152.     (and (>= from 3) 
  153.          (or (matches-in-suit  (- from 3) card ) 
  154.              (matches-in-rank  (- from 3) card )
  155.          )
  156.     )
  157. )
  158.  
  159. (define (playable-1? from card)
  160.     ( and (>= from 1)
  161.        (or (matches-in-suit  (- from 1) card  ) 
  162.            (matches-in-rank  (- from 1) card  )
  163.        )
  164.     )
  165. )
  166.  
  167. (define (button-double-clicked slot-id) 
  168.     (cond ((empty-slot? slot-id) #f)
  169.           ((playable-3? slot-id (get-top-card slot-id))
  170.              (do-action (- slot-id 3) slot-id (list (get-top-card slot-id)))
  171.           )          
  172.           ((playable-1? slot-id (get-top-card slot-id))
  173.              (do-action (- slot-id 1) slot-id (list (get-top-card slot-id)))
  174.           )
  175.       (else #f)          
  176.     )
  177. )
  178.  
  179.  
  180.  
  181. (define (game-continuable)
  182.   (give-status-message)
  183.   (and (not (game-won))
  184.        (get-hint)
  185.   )
  186. )
  187.  
  188.  
  189.  
  190. (define (game-won)
  191.   (and (empty-slot? 1) 
  192.        (not (empty-slot? 0))
  193.   )
  194. )
  195.  
  196. (define (make-hint possible-move)
  197.     (if (car possible-move)
  198.            (list 2 (get-name (get-top-card (car possible-move)))
  199.                    (get-name (get-top-card (car (cdr possible-move)))) 
  200.            ) 
  201.            #f
  202.     )
  203. )
  204.  
  205.  
  206. (define (find-playable-move start-slot)
  207.     (cond ( (empty-slot? start-slot) 
  208.               (list #f)
  209.           )
  210.           ( (playable-3? start-slot (get-top-card start-slot)) 
  211.               (list start-slot (- start-slot 3))
  212.           )
  213.           ( (playable-1? start-slot (get-top-card start-slot)) 
  214.               (list start-slot (- start-slot 1))
  215.           )
  216.           ( else 
  217.               (find-playable-move (+ start-slot 1))
  218.           )  
  219.     )    
  220. )
  221.  
  222.  
  223. (define (get-hint)
  224.        (make-hint (find-playable-move 1 ))
  225. )
  226.  
  227. (define (droppable?  start-slot card-list  end-slot) 
  228.   ( and 
  229.        (not (empty-slot? end-slot))    
  230.          (or (= (+ end-slot 1) start-slot)
  231.              (= (+ end-slot 3) start-slot)
  232.          )
  233.          (or (matches-in-rank end-slot (car card-list))
  234.              (matches-in-suit end-slot (car card-list))
  235.          )
  236.   )
  237. )
  238.  
  239. (define (get-options) #f )
  240.  
  241. (define (apply-options options) #f)
  242.  
  243. (define (timeout) #f)
  244.  
  245. (set-features droppable-feature)
  246.  
  247. (set-lambda new-game button-pressed button-released button-clicked 
  248.             button-double-clicked game-continuable game-won get-hint 
  249.             get-options apply-options timeout droppable?
  250. )
  251.